#pragma once
#include "Interface.h"
#include "Position.h"

//===========================================================================
// Route
//===========================================================================
class Route
{
public :
     
    Route(
        Route *    parent,
        IBoard *   board,
        EPieceType piece,
        Position   position
    );

    Route( const Route & route );

    ~Route( void );

    const Route * GetLeftNode(  void ) const {
        return this->m_left;
    }
    
    const Route * GetRightNode( void ) const {
        return this->m_right;
    }
    
    unsigned int GetDepth( void ) const {
        return this->m_depth;
    };
    
    const IPosition & GetPosition( void ) const {
        return this->m_position;
    }

    unsigned int SearchAllRoutes(
        bool jumped = false
    );

private :

    struct Node
    {
        Position position;
        ECourse  course;
        Route ** route;
        Position dest;

        Node(
            ECourse  course,
            Route ** route
        )   : course( course )
            , route( route )
        {}
    };    
    
    Position GetDestPosition(
        const IPosition & position,
              ECourse     course
    );
    
    bool GetDestPosition(
        const IPosition & position,
              ECourse     course,
              Position &  dest
    );

    const EPieceType * GetDest(
        const IPosition & position,
              ECourse     course,
              Position &  dest
    );
    
    void IncreaeDepth(
        unsigned int depth
    );

    void CleanUp( void );

    IBoard *   m_board;
    EPieceType m_piece;
    Position   m_position;
    
    unsigned int m_depth;
    
    Route *  m_parent;
    Route *  m_left;
    Route *  m_right;
};

